-
Notifications
You must be signed in to change notification settings - Fork 240
Use safeAsTime and safeAsDuration #1953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@cretz Do you remind spending some time to have a look on this PR 😄 |
@@ -29,6 +30,15 @@ func safeAsTime(timestamp *timestamppb.Timestamp) time.Time { | |||
} | |||
} | |||
|
|||
// safeAsDuration ensures that a nil proto duration makes `AsDuration()` return 0. | |||
func safeAsDuration(duration *durationpb.Duration) time.Duration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this added? .AsDuration()
should already be safe for nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this added?
.AsDuration()
should already be safe for nil
thanks for review, I will check this soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and will panic if call it from nil varible,
That is not true
var d *durationpb.Duration
fmt.Println(d.AsDuration())
prints 0s
so it is like the .AsTime
That is also not true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and will panic if call it from nil varible,
That is not true
var d *durationpb.Duration fmt.Println(d.AsDuration())
prints 0s
so it is like the .AsTime
That is also not true
It is my mistake! And I removed the safeAsDuration, please have a review again
@Quinn-With-Two-Ns any other question? |
Completely fix #1846